<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class News extends MY_Controller {

	function News()
	{
		parent::MY_Controller();
        $this->load->helper('page');
	}

	function view($id,$page=0){
		page_common();
		$this->load->model('mnews');
		$detail = $this->mnews->get_news_detail($id);
        $content = $detail['news_content'];
        $mark = $this->config->item('news_page_mark');
        if(strpos($content,$mark)) {
            $arr = explode($mark,$content);
            $detail['news_content'] = $arr[$page];
            $total = count($arr);
            $page_html = self::get_page_html('/news/view/'.$id,$total,$page);
            $this->template->assign('page_html',$page_html);
        }
		$this->template->view('v1/news',array('info'=>$detail));
	}

    function get_page_html($url,$total,$page=0) {
        $html = '<div class="pagebar">';
        for($i=0;$i<$total;$i++) {
            if($i == $page) {
                $html .= '<span class="current">第'.($i+1).'页</span>';
            } else {
                $html .= '<a href="'.$url.'/'.$i.'">第'.($i+1).'页</a>';
            }
        }
        $html .= '</div>';
        return $html;
    }


}
?>